package com.tensquare.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author BAO
 * @version V1.0
 * @Package com.tensquare.entity
 * @date 2020/12/2 17:50
 * @description:
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private Boolean flag;
    private Integer code;
    private String message;
    private T data;

    public static Result success(String msg,Object data){
        Result result = new Result<>();
        result.setCode(StatusCode.OK);
        result.setFlag(true);
        result.setMessage(msg);
        result.setData(data);
        return result;

    }

    public static Result fail(String msg){
        Result result = new Result<>();
        result.setCode(StatusCode.ERROR);
        result.setFlag(false);
        result.setMessage(msg);
        return result;
    }

    public static Result fail(int code,String msg){
        Result result = new Result<>();
        result.setCode(code);
        result.setFlag(false);
        result.setMessage(msg);
        return result;
    }
}
